﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FreedomERP.Models;
using FreedomERP.Filter;

namespace FreedomERP.Controllers
{
    [CheckSessionFilterAttribute]
    public class BaseController
    {
        public static BdAccount GetCurrLoginAccount()
        {
            BdAccount account = (BdAccount)HttpContext.Current.Session["user"];
            return account;
        }

        public static string GetCurrLoginAccountFId()
        {
            BdAccount account = (BdAccount)HttpContext.Current.Session["user"];
            if (account != null)
            {
                return account.FId;
            }
            else 
            {
                return null;
            }
        }

        public static string GetCurrLoginAccountOrgunitFId()
        {
            BdAccount account = (BdAccount)HttpContext.Current.Session["user"];
            if (account != null)
            {
                return account.FOrgunitId;
            }
            else
            {
                return null;
            }
        }

        public static string GetCurrLoginAccountOrgunitFName()
        {
            BdAccount account = (BdAccount)HttpContext.Current.Session["user"];
            if (account != null && account.BdOrgunit!=null)
            {
                return account.BdOrgunit.FName;
            }
            else
            {
                return null;
            }
        }

        public static string GetCurrLoginOrgunitFId()
        {
            BdAccount account = (BdAccount)HttpContext.Current.Session["user"];
            if (account != null)
            {
                return account.FOrgunitId;
            }
            else
            {
                return null;
            }
        }
    }
}